package cate.game.activity.mooncake;

import cate.common.table.activity.mooncake.row.MooncakeBossRow;
import cate.common.table.d.*;
import cate.game.activity.mooncake.msg.MooncakeChallengeDataResp;
import cate.game.activity.mooncake.msg.MooncakeChallengeResultResp;
import cate.game.play.proce.play.PlayPO;
import cate.game.res.MixRes;
import cate.game.res.MixResAdder;
import cate.game.role.Role;
import cate.game.role.farm.AbstractFarmFTC;

public class MooncakeBossFTC extends AbstractFarmFTC {
    /**
     * 当前挑战关卡的模板
     */
    private MooncakeBossRow tpl;

    public MooncakeBossFTC(Role role, MooncakeBossRow tpl) {
        setup(role);
        this.tpl = tpl;
    }

    @Override
    protected MooncakeChallenge po(Role role) {
        MooncakeActivity single = role.getActivity().getEnableActivitySingle(GDFunc.MOONCAKE);
        return single.challenge;
    }

    @Override
    public void handleResult(Role role, PlayPO play) {
        super.handleResult(role, play);
        if (po(role) == null) {
            return;
        }
        boolean win = play.winner == GDFight.Team.A;
        MooncakeChallengeResultResp resultResp = new MooncakeChallengeResultResp();
        resultResp.win = win;
        resultResp.funcId = toFuncId(tpl.type);
        resultResp.passFloor = tpl.level;
        if (win) {
            po(role).playTimes.added();
            po(role).challengeTimes++;
            po(role).setPassSafe(tpl.type, tpl.level);
            role.sendNow(new MooncakeChallengeDataResp(po(role)));
            resultResp.passFloor = tpl.level;
            //非一键战斗 只有一场
            resultResp.reward = new MixRes(this.tpl.firstReward);
            MixResAdder mra =
                    new MixResAdder()
                            .setRes(resultResp.reward)
                            .setOperation(GDOperation.MOONCAKE_CHALLENGE_REWARD);
            mra.exe(role);
//            role.getHistory().action.passForbidden();
        }
        role.sendNow(resultResp);
    }

    private int toFuncId(int roomId) {
        switch (roomId) {
            case GDCamp.Type.C1:
                return GDFunc.MOONCAKE_C1;
            case GDCamp.Type.C2:
                return GDFunc.MOONCAKE_C2;
            case GDCamp.Type.C3:
                return GDFunc.MOONCAKE_C3;
            case GDCamp.Type.C4:
                return GDFunc.MOONCAKE_C4;
            case GDCamp.Type.C5:
                return GDFunc.MOONCAKE_C5;
            case GDCamp.Type.C6:
                return GDFunc.MOONCAKE_C6;
            default:
                return 0;
        }
    }
}
